package cn.weisoft.jpademo.controller;

import cn.weisoft.jpademo.Repository.UserRepository;
import cn.weisoft.jpademo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.util.Date;

@RestController
public class DefaultController {

    @Autowired
    private UserRepository userRepository;

    @GetMapping("/")
    public String index(){

        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
        String formattedDate = dateFormat.format(date);
        userRepository.save(new User("aa", "aa@126.com", "aa", "aa123456",formattedDate,date));
        userRepository.save(new User("bb", "bb@126.com", "bb", "bb123456",formattedDate,date));
        userRepository.save(new User("cc", "cc@126.com", "cc", "cc123456",formattedDate,date));
       /* Assert.assertEquals(9, userRepository.findAll().size());
        Assert.assertEquals("bb", userRepository.findByUserNameOrEmail("bb", "cc@126.com").getNickName());*/
       User user = userRepository.findById(1l).orElse(null);
       System.out.println(user.getNickName());

       user.setNickName("傅威" + "");
       user.setRegDateTime(new Date());

       userRepository.save(user);

        //userRepository.delete(userRepository.findByUserName("aa"));
        return "OK";

    }
}
